001 /*
002 * Copyright 2006 Stephen McConnell.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
013 * implied.
014 *
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019 package net.dpml.depot;
020
021 import java.io.Serializable;
022 import java.util.logging.LogRecord;
023
024 import net.dpml.lang.PID;
025
026 /**
027 * Datastructure holding a log record and process identifier. The datastructure
028 * is used to bind a PID value that identifies a source JVM with a log record
029 * raised by the JVM.
030 *
031 * @author <a href="http://www.dpml.net">Digital Product Meta Library</a>
032 * @version 1.0.2
033 */
034 public final class LogStatement implements Serializable
035 {
036 /**
037 * Serial version identifier.
038 */
039 static final long serialVersionUID = 1L;
040
041 private final PID m_pid;
042 private final LogRecord m_record;
043
044 /**
045 * Creation of a new log statement.
046 * @param pid the JVM process identifier
047 * @param record the log record
048 */
049 public LogStatement( PID pid, LogRecord record )
050 {
051 m_pid = pid;
052 m_record = record;
053 }
054
055 /**
056 * Get the process identifier identifying the source JVM.
057 * @return the process identifier
058 */
059 public PID getPID()
060 {
061 return m_pid;
062 }
063
064 /**
065 * Get the log record raised by the source JVM.
066 * @return the log record
067 */
068 public LogRecord getLogRecord()
069 {
070 return m_record;
071 }
072
073 /**
074 * Compare this object with a supplied object for equality.
075 * This function returns true if the supplied object is a
076 * LogStatement with an equivalent process identifier and
077 * log record.
078 * @param other the other object
079 * @return true if the supplied object is equal to this object
080 */
081 public boolean equals( Object other )
082 {
083 if( null == other )
084 {
085 return false;
086 }
087 else if( other instanceof LogStatement )
088 {
089 LogStatement statement = (LogStatement) other;
090 if( !m_pid.equals( statement.m_pid ) )
091 {
092 return false;
093 }
094 else
095 {
096 return m_record.equals( statement.m_record );
097 }
098 }
099 else
100 {
101 return false;
102 }
103 }
104
105 /**
106 * Get the hascode for this instance.
107 * @return the instance hash value
108 */
109 public int hashCode()
110 {
111 int hash = m_pid.hashCode();
112 hash ^= m_record.hashCode();
113 return hash;
114 }
115 }
116